package com.mall.mapper;

import com.mall.domain.po.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 勾新杰
 * @version 1.0
 * @date 2024/11/22 23:10
 */
@Mapper
public interface CategoryMapper {

    /**
     * 新增分类
     * @param category 分类
     */
    @Insert("insert into category (name, status, create_time, update_time) " +
            "values (#{name}, #{status}, #{createTime}, #{updateTime});")
    void insert(Category category);

    /**
     * 更新分类
     * @param category 分类
     */
    void update(Category category);

    /**
     * 查询分类列表
     * @return 分类列表
     */
    @Select("select id, name, status, create_time, update_time from category;")
    List<Category> list();

    /**
     * 删除分类
     * @param id 分类id
     */
    @Delete("delete from category where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据id查询分类
     * @param id 分类id
     * @return 分类
     */
    @Select("select id, name, status, create_time, update_time from category where id = #{id};")
    Category getById(Long id);
}
